package com.java.code.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author weichuanyuan
 * @e-mail wei.cy@bsoft.com.cn
 * @date 2022/2/9 9:37
 * @package com.java.code.aop
 * @description
 */
@Aspect
@Component
@Slf4j
@Order(1)//可以定义aop的执行顺序
public class LogAspect {

    //@Pointcut("@annotation(com.java.code.aop.LogAnnotation)")
    @Pointcut("@within(com.java.code.aop.LogAnnotation)")
    //@Pointcut("execution(* com.java.code.web.controller..*.*(..))")
    public void logPointCut()
    {
    }

//    @After("logPointCut()")
//    public void afterLog(JoinPoint joinPoint){
//        log.info("aop记录一下日志");
//    }

    @Around("logPointCut()")
    public Object  aroundLog(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("记录日志开始");
        Object proceed = joinPoint.proceed();  //执行目标方法
        log.info("记录日志结束");
        return proceed;
    }

}
